<!DOCTYPE html>
<html lang="en" >
<head >
    <meta charset="utf-8" >
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" >
    <meta name="description" content="" >
    <meta name="author" content="ThemeBucket" >
    <link rel="shortcut icon" href="#" type="image/png" >

    <title >Form Layouts</title >
    <!--file upload-->
    <link rel="stylesheet" type="text/css" href="/public/css/bootstrap-fileupload.min.css" />

    <?php $this->load->view('library/header'); ?>
</head >
<style >
    .jiahao
    {
        padding-top : 6px;
        cursor      : pointer;
    }

    .m-l-1
    {
        margin-left : 16.65%;
        margin-top  : 10px;
    }

    .jianhao
    {
        cursor : pointer;
    }
</style >
<body class="sticky-header" >

<section >
    <?php $this->load->view('library/left'); ?>

    <!-- main content start-->
    <div class="main-content" >

        <?php $this->load->view('library/top'); ?>

        <!-- page heading start-->
        <div class="page-heading" >
            <h3 >
                创建产品 </h3 >
            <ul class="breadcrumb" >
                <li >
                    <a href="#" >Forms</a >
                </li >
                <li class="active" > Forms Layouts</li >
            </ul >
        </div >
        <!-- page heading end-->

        <!--body wrapper start-->
        <section class="wrapper" >
            <!-- page start-->

            <div class="row" >
                <div class="col-lg-12" >

                    <section class="panel" >
                        <div class="panel-body" >
                            <form
                                    class="cmxform form-horizontal adminex-form" id="commentForm"
                                    enctype="multipart/form-data" method="post" action="" >
                                <div class="form-group" >
                                    <label for="cemail" class="control-label col-lg-2" >货号</label >
                                    <div class="col-lg-2" >
                                        <select
                                                name="admin_id" id="admin_id" data-live-search="true"
                                                class="form-control" >
                                            <option >选择开发员</option >
                                            <?php foreach ($admin_name as $_id => $val): ?>
                                                <option <?php echo ($goods['admin_id'] == $_id || $admin_id == $_id) ? 'selected' : ''; ?>
                                                        value="<?php echo $_id; ?>" ><?php echo $val; ?></option >
                                            <?php endforeach; ?>
                                        </select >
                                    </div >
                                    <div class="col-lg-3" >
                                        <input
                                                class="form-control " id="goods_sn"
                                                type="text" <?php echo $goods ? 'disabled' : ''; ?>
                                                value="<?php echo $goods_sn; ?>" name="goods_sn" />
                                    </div >
                                </div >
                                <div class="form-group " >
                                    <label for="curl" class="control-label col-lg-2" >商品分类</label >
                                    <div class="col-lg-4" >
                                        <select name="cate_id" class="form-control" >
                                            <option >选择分类</option >
                                            <?php foreach ($cate_option as $cate_id => $cate_name): ?>
                                                <option <?php echo $goods['cat_id'] == $cate_id ? 'selected="selected"' : ''; ?>
                                                        value="<?php echo $cate_id; ?>" ><?php echo $cate_name; ?></option >
                                            <?php endforeach; ?>
                                        </select >
                                    </div >
                                </div >
                                <div class="form-group" >
                                    <label class="col-sm-2 col-sm-2 control-label" >渠道</label >
                                    <div class="col-sm-3" >
                                        <select name="channel_id" class="form-control" >
                                            <option value="0" >请选择渠道</option >
                                            <?php foreach ($channel as $k => $val): ?>
                                                <option value="<?php echo $k; ?>" ><?php echo $val; ?></option >
                                            <?php endforeach; ?>
                                        </select >
                                    </div >
                                </div >
                                <div class="form-group" >
                                    <label class="col-sm-2 col-sm-2 control-label" >生产方式</label >
                                    <div class="col-sm-3" >
                                        <select name="production_id" class="form-control" >
                                            <option value="1" >采买</option >
                                            <option value="2" >定制</option >
                                        </select >
                                    </div >
                                </div >
                                
                                <div class="form-group" >
                                    <label class="col-sm-2 col-sm-2 control-label" >面料</label >

                                    <div class="col-sm-3" >
                                        <select name="fabric" class="form-control" >

                                        </select >
                                    </div >

                                    <div class="col-sm-3" >
                                        <select name="fabric_id" class="form-control" >
                                            <option value="0" >选择面料</option >
                                        </select >
                                    </div >
                                </div >
                                <script >
                                    var result = '<?php echo $arr1;?>';
                                    result = JSON.parse (result);
                                    $ (document).ready (function () {
                                        var res = '';
                                        res += '<option value="0">选择面料</option>'
                                        $.each (result, function (k, v) {
                                            res += '<option value="' + v.id + '">' + v.fabric_name + '</option>';
                                        });
                                        $ ("select[name='fabric']").html (res);
                                    });

                                    $ ("select[name='fabric']").change (function () {
                                        var id = $ (this).val ();
                                        var fabric_val = '';
                                        $.each (result, function (key, val) {
                                            $.each (val, function (ke, va) {
                                                if (ke == id) {
                                                    $.each (va, function (k, v) {
                                                        fabric_val += '<option value="' + v.id + '">' + v.fabric_name + '</option>';
                                                    });
                                                }
                                            });
                                        });
                                        $ ("select[name='fabric_id']").html (fabric_val);
                                    })
                                </script >
                                <div class="form-group" >
                                    <label class="col-sm-2 col-sm-2 control-label" >产品图片</label >
                                    <div class="col-sm-10" >
                                        <div class="fileupload fileupload-new" data-provides="fileupload" >
                                            <div class="fileupload-new thumbnail" style="width: 200px; height: 150px;" >
                                                <img
                                                        src="http://www.placehold.it/200x150/EFEFEF/AAAAAA&amp;text=no+image"
                                                        alt="" />
                                            </div >
                                            <div
                                                    class="fileupload-preview fileupload-exists thumbnail"
                                                    style="max-width: 200px; max-height: 150px; line-height: 20px;" ></div >
                                            <div >
                                                   <span class="btn btn-default btn-file" >
                                                   <span class="fileupload-new" ><i class="fa fa-paper-clip" ></i > Select image</span >
                                                   <span class="fileupload-exists" ><i class="fa fa-undo" ></i > Change</span >
                                                   <input type="file" name="file" class="default" />
                                                   </span > <a
                                                        href="#" class="btn btn-danger fileupload-exists"
                                                        data-dismiss="fileupload" ><i class="fa fa-trash" ></i > Remove</a >
                                            </div >
                                        </div >
                                    </div >
                                </div >
                                <div class="form-group " >
                                        <label for="curl" class="control-label col-lg-2" >风格</label >
                                        <div>
                                            <div class="input-group" >
                                            <?php foreach($goods_typestyle as $key => $value){ ?>
                                                <p><?php echo $value['type_name']?><p>
                                                <?php foreach($value['val'] as $k => $v){ ?>
                                                <div style="float:left;margin-right: 10px">
                                                    <input type="checkbox" value="<?php echo $v['id'];?>" name="type_style[]"><label><?php echo $v['type_name'];?><label>
                                                </div>
                                                <?php } ?>
                                            <?php } ?>
                                            </div >
                                        </div >
                                    </div >
                                <div class="form-group" >
                                    <label class="col-sm-2 col-sm-2 control-label" >销售状态</label >
                                    <div class="col-sm-3" >
                                        <select name="sale_status" class="form-control" >
                                            <option value="2" >现货</option >
                                            <option value="5" >定制</option >
                                            <option value="17" >预售</option >
                                        </select >
                                    </div >
                                </div >
                                <div class="caimai_dingzhi" >
                                    <div class="form-group addsupp" >
                                        <label for="curl" class="control-label col-lg-2" >1688链接</label >
                                        <div class="col-lg-3" >
                                            <input class="form-control curl" type="text" value="" name="supp_url" />
                                        </div >
                                        <div class="col-lg-2" >
                                            <input
                                                    class="form-control supp_sn" value="" type="text" name="supp_sn"
                                                    placeholder="货号" > <input
                                                    type="hidden" class="g_supp_id" name="g_supp_id" value="" />
                                        </div >
                                        <div class="col-lg-2" >
                                            <div class="input-group" >
                                                <span class="input-group-addon" >￥</span > <input
                                                        type="text" value="" name="in_price"
                                                        class="form-control in_price" placeholder="进货价" >
                                            </div >
                                        </div >
                                        <div class="col-lg-1" >
                                            <a class="get-goods" href="javascript:;" >获取信息</a >
                                        </div >
                                    </div >
                                    <div class="form-group" >
                                        <label for="curl" class="control-label col-lg-2" >1688商品名称</label >
                                        <div class="col-lg-6" >
                                            <input
                                                    class="form-control supp_name" type="text" value=""
                                                    name="supp_name" />
                                        </div >
                                    </div >
                                    <div class="form-group " >
                                        <label for="curl" class="control-label col-lg-2" >价格</label >
                                        <div class="col-lg-2" >
                                            <div class="input-group" >
                                                <span class="input-group-addon" >$</span > <input
                                                        type="text" value="" name="shop_price" class="form-control"
                                                        placeholder="售价" >
                                            </div >
                                        </div >
                                    </div >
                                    <div class="form-group supp_sku" >
                                        <label class="control-label col-lg-2" >尺码颜色信息</label >
                                        <div class="col-lg-10 icheck" >
                                            <div class="col-lg-7 sku_color" >

                                            </div >
                                            <div class="col-lg-5 sku_size" >

                                            </div >
                                        </div >
                                    </div >
                                </div >
                                <div class="form-group" >
                                    <label class="col-lg-2 col-sm-2 control-label" ></label >
                                    <div class="col-lg-10" >
                                        <button type="submit" class="btn btn-primary" >提交</button >
                                    </div >
                                </div >
                            </form >
                        </div >
                    </section >
                </div >
            </div >
        </section >
        <footer >
            2014 &copy; AdminEx by
        </footer >
    </div >
</section >
<script type="text/html" id="caimai" >
    <div class="form-group addsupp" >
        <label for="curl" class="control-label col-lg-2" >1688链接</label >
        <div class="col-lg-3" >
            <input class="form-control curl" type="text" value="" name="supp_url" />
        </div >
        <div class="col-lg-2" >
            <input class="form-control supp_sn" value="" type="text" name="supp_sn" placeholder="货号" > <input
                    type="hidden" class="g_supp_id" name="g_supp_id" value="" />
        </div >
        <div class="col-lg-2" >
            <div class="input-group" >
                <span class="input-group-addon" >￥</span > <input
                        type="text" value="" name="in_price" class="form-control in_price" placeholder="进货价" >
            </div >
        </div >
        <div class="col-lg-1" >
            <a class="get-goods" href="javascript:;" >获取信息</a >
        </div >
    </div >
    <div class="form-group" >
        <label for="curl" class="control-label col-lg-2" >1688商品名称</label >
        <div class="col-lg-6" >
            <input class="form-control supp_name" type="text" value="" name="supp_name" />
        </div >
    </div >
    <div class="form-group " >
        <label for="curl" class="control-label col-lg-2" >价格</label >
        <div class="col-lg-2" >
            <div class="input-group" >
                <span class="input-group-addon" >$</span > <input
                        type="text" value="" name="shop_price" class="form-control" placeholder="售价" >
            </div >
        </div >
    </div >
    <div class="form-group supp_sku" >
        <label class="control-label col-lg-2" >尺码颜色信息</label >
        <div class="col-lg-10 icheck" >
            <div class="col-lg-7 sku_color" >

            </div >
            <div class="col-lg-5 sku_size" >

            </div >
        </div >
    </div >
</script >
<script type="text/html" id="dingzhi" >
    <div class="form-group addsupp" >
        <label for="curl" class="control-label col-lg-2" >1688链接</label >
        <div class="col-lg-3" >
            <input class="form-control curl" type="text" value="" name="supp_url" >
        </div >
    </div >
    <div class="form-group " >
        <label for="curl" class="control-label col-lg-2" >进货价</label >
        <div class="col-lg-2" >
            <div class="input-group" >
                <span class="input-group-addon" >$</span > <input
                        type="text" value="" name="in_price" class="form-control" placeholder="进货价" >
            </div >
        </div >
    </div >
    <div class="form-group " >
        <label for="curl" class="control-label col-lg-2" >价格</label >
        <div class="col-lg-2" >
            <div class="input-group" >
                <span class="input-group-addon" >$</span > <input
                        type="text" value="" name="shop_price" class="form-control" placeholder="售价" >
            </div >
        </div >
    </div >
    <div class="form-group supp_sku ajax_sku" >
        <label class="control-label col-lg-2" >尺码颜色信息</label >
        <div >
            <div class="col-lg-10 icheck " >
                <div class="col-lg-7 sku_color" >
                    <div class="row" style=" " >
                        <div class="col-lg-5" >
                            <select
                                    name="aliyun_sku[color][]"
                                    class="option-color form-control sunjian_color supp_sku_color" >
                                <option value="" >选择颜色</option >
                                <?php foreach ($color_option as $k => $color) : ?>
                                    <option value="<?php echo $k; ?>" ><?php echo $color; ?></option >
                                <?php endforeach; ?>
                            </select >
                        </div >
                        <input
                                style="width: 170px;" placeholder="采购颜色" class="form-control curl" type="text"
                                name="aliyun_sku[ali_color][]" />
                    </div >
                </div >
                <div class="col-lg-5 sku_size" >
                    <div class="row" style="" >
                        <div class="col-lg-6" >
                            <select
                                    name="aliyun_sku[size][]"
                                    class="option-size form-control sunjian_size supp_sku_size" >
                                <option value="" >选择尺码</option >
                                <?php foreach ($size_option as $size) : ?>
                                    <option value="<?php echo $size; ?>" ><?php echo $size; ?></option >
                                <?php endforeach; ?>
                            </select >
                        </div >
                        <input
                                style="width: 170px;float: left;" placeholder="采购尺码" class="form-control curl"
                                type="text" name="aliyun_sku[ali_size][]" />
                        <div style="font-size: 35px; width: 0px" class="jiahao" >+</div >
                    </div >
                </div >
            </div >
        </div >
    </div >
</script >
<script type="text/html" id="add_sku" >

    <div class="col-lg-10 icheck m-l-1" >
        <div class="col-lg-7 sku_color" >
            <div class="row" style=" " >
                <div class="col-lg-5" >
                    <select name="aliyun_sku[color][]" class="option-color form-control sunjian_color supp_sku_color" >
                        <option value="" >选择颜色</option >
                        <?php foreach ($color_option as $k => $color) : ?>
                            <option value="<?php echo $k; ?>" ><?php echo $color; ?></option >
                        <?php endforeach; ?>
                    </select >
                </div >
                <input
                        style="width: 170px;" placeholder="采购颜色" class="form-control curl" type="text"
                        name="aliyun_sku[ali_color][]" />
            </div >
        </div >
        <div class="col-lg-5 sku_size" >
            <div class="row" style="" >
                <div class="col-lg-6" >
                    <select name="aliyun_sku[size][]" class="option-size form-control sunjian_size supp_sku_size" >
                        <option value="" >选择尺码</option >
                        <?php foreach ($size_option as $size) : ?>
                            <option value="<?php echo $size; ?>" ><?php echo $size; ?></option >
                        <?php endforeach; ?>
                    </select >
                </div >
                <input
                        style="width: 170px;float: left;" placeholder="采购尺码" class="form-control curl" type="text"
                        name="aliyun_sku[ali_size][]" />
                <div style="font-size: 35px;" class="jianhao" >-</div >
            </div >
        </div >
    </div >
</script >


<script type="text/html" id="color_temp" >
    <% for(var i = 0; i < items.length; i++){ %>
    <div class="row" style="margin-top: 15px; margin-left: -30px;" >
        <div class="col-lg-6" >
            <img width="35" src="<%=items[i].imageUrl%>" class="img-rounded" style="float: left; margin-right: 15px;" />
            <input
                    style="float: left; width: 200px;" value="<%=items[i].name%>" name="aliyun_sku[ali_color][]"
                    readonly="readonly" class="form-control sunjian_ali_color" >
        </div >
        <div class="col-lg-5" >
            <select name="aliyun_sku[color][]" class="option-color form-control sunjian_color supp_sku_color" >
                <option value="" >选择颜色</option >
                <?php foreach ($color_option as $k => $color) : ?>
                    <option value="<?php echo $k; ?>" ><?php echo $color; ?></option >
                <?php endforeach; ?>
            </select >
        </div >
    </div ><% } %>
</script >
<script type="text/html" id="size_temp" >
    <% for(var i = 0; i < items.length; i++){ %>
    <div class="row" style="margin-top: 15px;" >
        <div class="col-lg-4" >
            <input
                    value="<%=items[i].name%>" name="aliyun_sku[ali_size][]" readonly="readonly"
                    class="form-control sunjian_ali_size" >
        </div >
        <div class="col-lg-6" >
            <select name="aliyun_sku[size][]" class="option-size form-control sunjian_size supp_sku_size" >

                <option value="" >选择尺码</option >
                <?php foreach ($size_option as $size) : ?>
                    <option value="<?php echo $size; ?>" ><?php echo $size; ?></option >
                <?php endforeach; ?>
            </select >
        </div >
    </div ><% } %>
</script >
<?php $this->load->view('library/footer'); ?>
<script src="/public/js/iCheck/jquery.icheck.js" ></script >
<script src="/public/js/icheck-init.js" ></script >

<script src="/public/js/express-art-template-master/template-web.js" ></script >
<!--file upload-->
<script type="text/javascript" src="/public/js/bootstrap-fileupload.min.js" ></script >
<script type="text/javascript" >
    $ ("select[name='production_id']").change (function () {
        var id = $ (this).val ();
        if (id == 1) {
            var caimai = $ ('#caimai').text ();
            $ ('.caimai_dingzhi').html (caimai);
        }
        else {
            var dingzhi = $ ('#dingzhi').text ();
            $ ('.caimai_dingzhi').html (dingzhi);
        }
    })


    $ (document).on ('click', '.jiahao', function () {
        var aa = $ ('#add_sku').text ();
        $ ('.ajax_sku').append (aa);
    })
    $ (document).on ('click', '.jianhao', function () {
        $ (this).parents ('.icheck').remove ();
    })
    $ (function () {
        $ (document).on ('click', '.get-goods', function () {
            var in_price = $("input[name='in_price']").val();
            if(!in_price){
                alert('填写进货价');
                return false;
            }
            // $('.get-goods').on('click', function () {
            var supp = $ (this).parents ('.addsupp').find ('.curl').val ();

            thisg = $ (this);

            $ (this).html ('获取中...');
            var supp_id = $ ('.selectpicker').val ();
            $.post ("<?php echo base_url('PrepareGoods/ajax_ali_goods');?>", {
                ali_url: supp,
                supp_id: supp_id,
                in_price:in_price
            }, function (aliData) {
                if (aliData.info == '商品信息获取失败') {
                    swal ({
                        title: aliData.info,
                        text: '2秒后关闭',
                        type: aliData.status,
                        allowOutsideClick: false,
                        timer: 3000,
                        showConfirmButton: false
                    });
                }
                var result_color = '', result_size = '';
                var data = aliData.data;

                thisg.parents ('.addsupp').find ('.supp_sn').val (data.ali_sn);
                thisg.parents ('.addsupp').find ('.in_price').val (data.ali_price);
                thisg.parents ('.addsupp').find ('.g_supp_id').val (data.g_supp_id);
                $("input[name='shop_price']").val(data.shop_price);
                
                $ ('.supp_name').val (data.title);

                if (data.skuProps) {
                    for (var x in data.skuProps) {

                        var obj = {
                            items: data.skuProps[ x ].value
                        };

                        if (data.skuProps[ x ].prop === '颜色') {
                            result_color += template ('color_temp', obj);
                        }
                        else if (data.skuProps[ x ].prop === '尺码') {
                            result_size += template ('size_temp', obj);
                        }
                    }
                    $ ('.supp_sku .sku_color').html (result_color);
                    $ ('.supp_sku .sku_size').html (result_size);
                    $ ('.flat-green input').iCheck ({
                        checkboxClass: 'icheckbox_flat-green',
                        radioClass: 'iradio_flat-green'
                    });
                }


            }, 'json');
        });

        $ ('#commentForm').submit (function () {
            $ ('button[type="submit"]').attr ('disabled', 'disabled').addClass ('btn-submit-disabled').html ('正在提交，请稍等...');

            var data = new FormData (this);

            $.ajax ({
                url: '<?php echo base_url('PrepareGoods/set');?>',
                type: 'POST',
                cache: false,
                dataType: 'json',
                data: data,
                success: function (data) {
                    if (data.status != 'success') {
                        swal ({
                            title: data.info,
                            text: '2秒后关闭',
                            type: data.status,
                            allowOutsideClick: false,
                            timer: 1500,
                            showConfirmButton: false
                        });
                    }
                    else {
                        swal ({
                            title: data.info,
                            text: '2秒后关闭',
                            type: data.status,
                            allowOutsideClick: false,
                            timer: 1500,
                            showConfirmButton: false
                        }).then (function (isConfirm) {
                            window.onbeforeunload = '';
                            window.location.href = '<?php echo base_url('PrepareGoods/index_accurate?prepare_state=1');?>';
                        });
                    }
                    $ ('button[type="submit"]').attr ("disabled", false).removeClass ('btn-submit-disabled').html ('提交信息');
                },
                processData: false,
                contentType: false
            });
            setTimeout (function () {
                $ ('button[type="submit"]').attr ("disabled", false).removeClass ('btn-submit-disabled').html ('提交信息');
            }, '3000');
            return false;
        });


        //获取货号
        $ ('#admin_id').change (function () {

            $.post ('<?php echo base_url('PrepareGoods/get_goods_sn');?>', {admin_id: $ (this).val ()}, function (goods_sn) {
                $ ('#goods_sn').val (goods_sn);
            }, 'text');
        });

    });

</script >

<!--common scripts for all pages-->
<script src="/public/js/scripts.js" ></script >

</body >
</html >
